﻿#include <algorithm>
#include <gtest/gtest.h>
#include <iostream>
#include <vector>

#include <learn/math/integrator.h>
#include <learn/utils/output.h>

using namespace xi;
using namespace xi::math;

TEST(TestIntegrator, NewtonCotes)
{
    {
        Integrator_Trapezoidal I(10000);

        auto f = [](double x) { return sin(Numeric::pi * x); };
        EXPECT_FLOAT_EQ(I(f, 0, 1), 2 / Numeric::pi);
    }

    {
        Integrator_Simpson I(100);

        auto f = [](double x) { return sin(Numeric::pi * x); };
        EXPECT_FLOAT_EQ(I(f, 0, 1), 2 / Numeric::pi);
    }

    {
        Integrator_Gauss I(5);
        // std::cout << I.m_nodes << std::endl;
        // std::cout << I.m_weights << std::endl;

        auto f = [](double x) { return sin(Numeric::pi * x); };
        EXPECT_FLOAT_EQ(I(f, 0, 1), 2 / Numeric::pi);
    }
}